package com.atserver.windows;

import com.atserver.listener.CoordinateMouseListener;
import com.atserver.listener.CoordinateMouseMove;

import javax.swing.*;
import java.awt.*;

/**
 * @program: atserver
 * @Description: 屏幕坐标获取界面
 * @author: Mr.Cheng
 * @date: 2022/6/14 10:28 上午
 */
public class CoordinateWindow extends JFrame {

    private ScannerWindow scannerWindow;

    /**
     * Creates a new, initially invisible <code>Frame</code> with the
     * specified title.
     * <p>
     * This constructor sets the component's locale property to the value
     * returned by <code>JComponent.getDefaultLocale</code>.
     *
     * @param title the title for the frame
     * @throws HeadlessException if GraphicsEnvironment.isHeadless()
     *                           returns true.
     * @see GraphicsEnvironment#isHeadless
     * @see Component#setSize
     * @see Component#setVisible
     * @see JComponent#getDefaultLocale
     */
    public CoordinateWindow(String title, ScannerWindow scannerWindow) throws HeadlessException {
        super(title);
        this.scannerWindow = scannerWindow;
        init();
    }

    /**
     * Creates a new, initially invisible <code>Frame</code> with the
     * specified title.
     * <p>
     * This constructor sets the component's locale property to the value
     * returned by <code>JComponent.getDefaultLocale</code>.
     *
     * @param title the title for the frame
     * @throws HeadlessException if GraphicsEnvironment.isHeadless()
     *                           returns true.
     * @see GraphicsEnvironment#isHeadless
     * @see Component#setSize
     * @see Component#setVisible
     * @see JComponent#getDefaultLocale
     */
    public CoordinateWindow(String title) throws HeadlessException {
        super(title);
        init();
    }

    private void init(){
        setExtendedState(JFrame.MAXIMIZED_BOTH);
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        setUndecorated(true);
        setBackground(new Color(0,0,150,50));
        this.addMouseListener(new CoordinateMouseListener(this));
        this.addMouseMotionListener(new CoordinateMouseMove(scannerWindow));
    }
}
